# -*- coding:UTF-8 -*-


###########################################################################
## Python code generated with wxFormBuilder (version Oct 26 2018)
## http://www.wxformbuilder.org/
##
## PLEASE DO *NOT* EDIT THIS FILE!
###########################################################################

import wx
import wx.xrc
import logging
from src.bridge.getconfdata import ConfData
logging.basicConfig(filename="./log/confpage.log", filemode='w',
                    format='%(asctime)s : %(levelname)s : %(message)s',
                    level=logging.DEBUG)


###########################################################################
## Class ConfigurationPanel
###########################################################################

class ConfigurationPanel(wx.Panel):

    def __init__(self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition, size=wx.Size(-1, -1), style=wx.TAB_TRAVERSAL,
                 name=wx.EmptyString):
        wx.Panel.__init__(self, parent, id=id, pos=pos, size=size, style=style, name=name)

        self.conf = ConfData()

        bSizer = wx.BoxSizer(wx.HORIZONTAL)

        self.info_textCtrl = wx.TextCtrl(self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.Size(500, -1),
                                         wx.TE_MULTILINE)
        bSizer.Add(self.info_textCtrl, 0, wx.ALL | wx.EXPAND, 5)
        self.info_textCtrl.SetValue(self.conf.open_confile())

        self.save_button = wx.Button(self, wx.ID_ANY, u"保 存", wx.DefaultPosition, wx.DefaultSize, 0)
        bSizer.Add(self.save_button, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5)

        self.SetSizer(bSizer)
        self.Layout()
        bSizer.Fit(self)

        # Connect Events
        self.save_button.Bind(wx.EVT_BUTTON, self.save_info)

    def __del__(self):
        pass

    # Virtual event handlers, overide them in your derived class
    def save_info(self, event):
        try:
            event.GetEventObject().Disable()
            value = self.info_textCtrl.GetValue()
            self.conf.save_confile(value)
            wx.MessageBox("保存成功")
        except BaseException as e:
            wx.MessageBox("保存失败")
            logging.error(e)
        finally:
            event.GetEventObject().Enable()
            event.Skip()
